package com.ait.edu.controller;


import com.ait.commonutils.Msg;
import com.ait.edu.entity.Chapter;
import com.ait.edu.entity.chapter.ChapterVo;
import com.ait.edu.service.ChapterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-06-14
 */
@RestController
@RequestMapping("/eduservice/chapter")
public class ChapterController {


    @Autowired
    private ChapterService chapterService;

    @ApiOperation("获取章节和小节")
    @GetMapping("getChapterVideoId")

    public Msg getChapterVideoId(String id){
        List<ChapterVo> chapterVideoByCourseId = chapterService.getChapterVideoByCourseId(id);
        return Msg.success().data("list",chapterVideoByCourseId);
    }

    @ApiOperation("添加章节")
    @PostMapping("addChapter")
    public Msg addChapter(@RequestBody Chapter chapter){

        boolean save = chapterService.save(chapter);
        if(save){
            return Msg.success();
        }
        return Msg.fail();
    }

    @ApiOperation("获取章节")
    @GetMapping("getChapterById")
    public Msg getChapterById(String id){

        Chapter byId = chapterService.getById(id);
        if(byId!=null){
            return Msg.success().data("chapter",byId);
        }
        return Msg.fail();
    }


    @ApiOperation("修改章节")
    @PutMapping("modifyChapter")
    public Msg modifyChapter(@RequestBody Chapter chapter){

        boolean save = chapterService.updateById(chapter);
        if(save){
            return Msg.success();
        }
        return Msg.fail();
    }

    @ApiOperation("删除章节")
    @DeleteMapping("delChapter")
    public Msg delChapter(String id){

        boolean save = chapterService.delChaptervideo(id);
        if(save){
            return Msg.success();
        }
        return Msg.fail();
    }
}

